package com.gao.gLotusMusic.view;

import com.gao.gLotusMusic.controller.TopController;
import com.gao.musicApi.model.Song;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.HBox;

import java.util.List;

public class TopUi extends HBox {
    public static TopUi instance = new TopUi();


    private TopController controller = TopController.getInstance();

    private final TextField searchField = new TextField();

    public TopUi() {
        initUI();
        initListener();
    }

    private void initUI() {
        searchField.setPromptText("搜索");

        getChildren().add(searchField);
    }

    private void initListener() {
        searchField.setOnKeyReleased(keyEvent -> {
            if (keyEvent.getCode() == KeyCode.ENTER) {
                controller.search(searchField.getText());
            }
        });
    }

    public void searchHandle(List<Song> songs) {
        CenterUI.instance.setSongTableItem(songs);
    }
}
